Skip to content

fix(mf4): defer asammdf imports until reader/writer construction - #2123

Open
timothyanderson096-ocdealcheck wants to merge 2 commits into
hardbyte:mainfrom
timothyanderson096-ocdealcheck:fix/mf4-import-order-2122
Open

timothyanderson096-ocdealcheck wants to merge 2 commits into
hardbyte:mainfrom
timothyanderson096-ocdealcheck:fix/mf4-import-order-2122

Conversation

@timothyanderson096-ocdealcheck

@timothyanderson096-ocdealcheck timothyanderson096-ocdealcheck commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary of Changes

Importing asammdf first can re-enter can through canmatrix/canopen before asammdf finishes initializing. The optional-import guard then permanently treats an installed dependency as missing.

  • Load asammdf when an MF4 reader or writer is constructed.
  • Report a genuinely missing asammdf package separately from a missing transitive dependency, before opening the output file.
  • Cover native import orders, a deterministic circular import, missing dependencies and file-opening controls.
  • Integrate current main while preserving UTC writer timestamps and the packed error-frame repair from fix(mf4): read packed error-frame payloads without losing byte order #2115. Its eight payload regressions retain their assertions and import helper classes/constants directly from asammdf.
  • Preserve evaluated public path annotations for Sphinx while keeping asammdf signature types behind type checking.

Closes #2122. Thanks to @nehalkpatel for the reproduction and dependency-chain analysis.

Type of Change

  • Bug fix

Checklist

  • Contribution guide followed; tests and changelog fragment included.
  • Focused regressions and applicable local static checks pass.
  • All checks and tests pass (tox): limitations below remain.

Current validation — 13 November 2026

Published revision dcbe0e4394b7286aaa4326557b7bc8805348fd4f merges upstream 86e85794f6c3505c988a4acd5d34f5b08f508b17 into the existing PR. Its complete tree c2d30628aaaeff97d88042704a8a4e3e9d018f2f matches the final locally verified tree.

Environment: Linux / CPython 3.12.14; asammdf 8.7.2, canmatrix 1.2, canopen 2.4.1. The shallow checkout used a local setuptools-scm version override for installation.

  • Final focused MF4 suite: 16 passed, 1 existing unsupported-append skip, 6 subtests passed. This includes the eight upstream packed-payload cases.
  • Identical import regressions on unchanged current upstream fail in four reader/writer subcases and the transitive-error case; all pass with this repair.
  • Full final local suite: 529 passed, 99 skipped, 42 subtests passed, 28 failed. Baseline with the same added import tests: 528 passed, 99 skipped, 38 subtests passed, 33 failed. Every remaining candidate failure is an IPv4/IPv6 multicast initialization failure also present on the baseline; there are no new failing test identities.
  • Project-wide Black and Ruff, changed-source Pylint and whitespace checks pass. Mypy targets Python 3.11–3.15 pass all 65 source files in a separate environment without MF4 extras, matching the type-check environment's optional-dependency boundary. With real MF4 dependencies installed, a separate diagnostic retains seven errors versus 16 on the baseline.
  • 39 documentation doctests pass. Strict HTML documentation generation retains one unresolved _thread.allocate_lock reference also present on unchanged upstream. The introduced path-annotation reference warning was repaired; no warning suppression was added.
  • Independent inspection and runtime probes found no material issue; importing can leaves asammdf unloaded, and writer UTC start time and message writing remain valid.

No native Python 3.14 tox run, hosted CI success for this new revision, physical CAN hardware, other OS/interpreter runtime matrix, or minimum asammdf 6 validation is claimed. Full local tests and strict HTML documentation are not completely green for the inherited/environment limitations above.

Prepared with OpenAI Codex assistance and independent inspection.

Timothy Anderson — Spotted Ridge Engineering / OC Labs
Independent software verification · GDN (Global Decision Network)
timothyanderson096@gmail.com · Engineering evidence

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T15:09:54.382157Z 2c0bb48 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Preserve UTC writer timestamps and packed error-frame decoding while retaining lazy asammdf imports. Adapt the upstream payload tests to use asammdf-owned helpers and keep runtime path annotations compatible with Sphinx.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MF4Writer reports "asammdf package was not found" when asammdf is imported before can

1 participant